//
//  XWHAOFWDRCGainOperationModel.swift
//  XWHAOfflineFitting
//
//  Created by edy on 2024/3/7.
//

import UIKit

enum XWHAOFGainsSheetRowType {
    
    case none
    case all
    case mpo
    case loud
    case midvoice
    case whisper
    
}

enum XWHAOFGainsSheetUpDownActionType {
    
    case none
    case upOne
    case downOne
    case upThree
    case downThree
    
}

class XWHAOFWDRCGainSheetOperationItemModel: HandyJSONCloneableBaseModel {
    
    class var allIndex: Int {
        0xff
    }
    
    var isLeft = true
    
    var rowType: XWHAOFGainsSheetRowType = .none
    
    var index: Int = XWHAOFWDRCGainSheetOperationItemModel.allIndex
//    var value: Double = 0
    
    var isSelected = false

    func initAndConfig(rowType: XWHAOFGainsSheetRowType, isLeft: Bool, index: Int) {
        self.rowType = rowType

        self.isLeft = isLeft
        self.index = index
    }
}

class XWHAOFWDRCGainSingleSheetOperationModel: XWHAOFWDRCGainSheetOperationItemModel {
    
    var allItem = XWHAOFWDRCGainSheetOperationItemModel()
    var mpoItem = XWHAOFWDRCGainSheetOperationItemModel()
    var loudItem = XWHAOFWDRCGainSheetOperationItemModel()
    var midvoiceItem = XWHAOFWDRCGainSheetOperationItemModel()
    var whisperItem = XWHAOFWDRCGainSheetOperationItemModel()
    
    var allItemList: [XWHAOFWDRCGainSheetOperationItemModel] = []
    var mpoItemList: [XWHAOFWDRCGainSheetOperationItemModel] = []
    var loudItemList: [XWHAOFWDRCGainSheetOperationItemModel] = []
    var midvoiceItemList: [XWHAOFWDRCGainSheetOperationItemModel] = []
    var whisperItemList: [XWHAOFWDRCGainSheetOperationItemModel] = []

    func initAndConfig(freqBandList: [Int], isLeft: Bool) {
        if allItemList.count == freqBandList.count {
            return
        }
        
        allItem.initAndConfig(rowType: .all, isLeft: isLeft, index: XWHAOFWDRCGainSheetOperationItemModel.allIndex)
        mpoItem.initAndConfig(rowType: .mpo, isLeft: isLeft, index: XWHAOFWDRCGainSheetOperationItemModel.allIndex)
        loudItem.initAndConfig(rowType: .loud, isLeft: isLeft, index: XWHAOFWDRCGainSheetOperationItemModel.allIndex)
        midvoiceItem.initAndConfig(rowType: .midvoice, isLeft: isLeft, index: XWHAOFWDRCGainSheetOperationItemModel.allIndex)
        whisperItem.initAndConfig(rowType: .whisper, isLeft: isLeft, index: XWHAOFWDRCGainSheetOperationItemModel.allIndex)

        allItemList.removeAll()
        mpoItemList.removeAll()
        loudItemList.removeAll()
        midvoiceItemList.removeAll()
        whisperItemList.removeAll()
        for (i, _) in freqBandList.enumerated() {
            var iItem = XWHAOFWDRCGainSheetOperationItemModel()
            iItem.initAndConfig(rowType: .all, isLeft: isLeft, index: i)
            allItemList.append(iItem)
            
            iItem = XWHAOFWDRCGainSheetOperationItemModel()
            iItem.initAndConfig(rowType: .mpo, isLeft: isLeft, index: i)
            mpoItemList.append(iItem)
            
            iItem = XWHAOFWDRCGainSheetOperationItemModel()
            iItem.initAndConfig(rowType: .loud, isLeft: isLeft, index: i)
            loudItemList.append(iItem)
            
            iItem = XWHAOFWDRCGainSheetOperationItemModel()
            iItem.initAndConfig(rowType: .midvoice, isLeft: isLeft, index: i)
            midvoiceItemList.append(iItem)
            
            iItem = XWHAOFWDRCGainSheetOperationItemModel()
            iItem.initAndConfig(rowType: .whisper, isLeft: isLeft, index: i)
            whisperItemList.append(iItem)
        }
    }
    
}

class XWHAOFWDRCGainSheetOperationModel: HandyJSONCloneableBaseModel {
    
    var leftOperation = XWHAOFWDRCGainSingleSheetOperationModel()
    var rightOperation = XWHAOFWDRCGainSingleSheetOperationModel()
    
    func initAndConfig(freqBandList: [Int]) {
        leftOperation.initAndConfig(freqBandList: freqBandList, isLeft: true)
        rightOperation.initAndConfig(freqBandList: freqBandList, isLeft: false)
    }

}

enum XWHAOFWDRCFittingModeType: Int {
    
    case hearingChartMode
    case resetFactoryValueMode
    case fittingOperationMode
    
    var name: String {
        switch self {
        case .hearingChartMode:
            return "听力图模式"
        case .resetFactoryValueMode:
            return "出厂值模式"
        case .fittingOperationMode:
            return "验配方案模式"
        }
    }
    
}

class XWHAOFWDRCGainChartOperationModel: HandyJSONCloneableBaseModel {
    
    var isShowRealEarGain = true
    var isShowTargetGain = true
    var isShowMaxMPO = true
    var isShowRealMPO = true
    
    var wdrcFittingModeType = XWHAOFWDRCFittingModeType.hearingChartMode
    
}
